﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Lexathon
{
    public partial class GamePage : PhoneApplicationPage
    {
        public GamePage()
        {
            InitializeComponent();

            foreach (var c in TilesPanel.Children)
            {
                AttachEventsToLetter(c);
            }
        }

        void AttachEventsToLetter(UIElement element)
        {
            element.ManipulationDelta += TextBlock_ManipulationDelta;
            element.ManipulationCompleted += TextBlock_ManipulationCompleted;


            element.RenderTransform = new TranslateTransform();
        }

        private void TextBlock_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            var tb = (TextBlock)sender;

            ((TranslateTransform)tb.RenderTransform).X += e.DeltaManipulation.Translation.X;
            ((TranslateTransform)tb.RenderTransform).Y += e.DeltaManipulation.Translation.Y;

        }

        private void TextBlock_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            var tb = (TextBlock)sender;

            ((TranslateTransform)tb.RenderTransform).X = 0;
            ((TranslateTransform)tb.RenderTransform).Y = 0;
        }
    }
}